<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">
<body>
	<ui:composition>
	<p:accordionPanel multiple="true" id="poAccordion" activeIndex="#{dtPurchaseOrderRequestView.activeIndex}"
		value="#{dtPurchaseOrderRequestView.purchaseOrders}" var="purchaseOrder">
        <p:tab title="#{purchaseOrder.id}">
            <h:panelGrid>
                <f:facet name="header">
                    <h:outputText value="Brand:" style="font-weight: bold" />
                </f:facet>  
                <p:dataTable var="poItem" value="#{purchaseOrder.items}" rendered="#{not empty purchaseOrder.items}">
                	<p:column headerText="Item #">
                		<h:outputText value="#{poItem.itemNumber}" />
                	</p:column>
                	<p:column headerText="Description">
                		<h:outputText value="#{poItem.partUnit.shortName}" />
                	</p:column>
                	<p:column headerText="Brand">
                		<h:outputText value="#{poItem.partUnit.shortBrand}" />
                	</p:column>
                	<p:column headerText="Part #">
                		<h:outputText value="#{poItem.partUnit.part}" />
                	</p:column>
                	<p:column headerText="Qty">
                		<h:outputText value="#{poItem.quantity}" />
                	</p:column>
                	<p:column headerText="Price/Unit">
                		<h:outputText value="#{poItem.pricePerUnit}" />
                	</p:column>
                	<p:column headerText="Total">
                		<h:outputText value="#{poItem.totalPrice}" />
                	</p:column>
                	<p:column headerText="Delete">
                		<p:commandButton value="Delete" update=":fsOpen :poAccordion" 
                			action="#{dtPurchaseOrderRequestView.deletePoItem(poItem.id)}" />
                	</p:column>
                	
                </p:dataTable>
                <f:facet name="footer">
                    <p:commandButton value="Discard" 
                    	rendered="#{empty purchaseOrder.items}" update=":fsOpen :poAccordion" 
                    	action="#{dtPurchaseOrderRequestView.deletePurchaseOrder(purchaseOrder.id)}" 
                    	
                    />
                    <p:commandButton value="Submit" rendered="#{not empty purchaseOrder.items}"/>
                </f:facet>  
            </h:panelGrid>
        </p:tab>
    </p:accordionPanel>
	</ui:composition>
</body>
</html>